#pragma once

#include <iostream>
#include <pthread.h>
#include "mutex.hpp"

namespace Condmodle
{
    using namespace Lock;
    // 进行同步操作
    class cond
    {
    private:
        pthread_cond_t _cond;
    public:
        cond()
        {
            int n = pthread_cond_init(&_cond, nullptr);
            (void)n;
        }
        void Wait(mutex &mutex) // 让我们的线程释放曾经持有的锁！
        {
            int n = ::pthread_cond_wait(&_cond, mutex.adder());
        }
        void Notify()
        {
            int n = ::pthread_cond_signal(&_cond);
            (void)n;
        }
        void NotifyAll()
        {
            int n = ::pthread_cond_broadcast(&_cond);
            (void)n;
        }
        ~cond()
        {
            int n = ::pthread_cond_destroy(&_cond);
        }
    };
}